//
//  CedarFileManager.m
//  CedarFinancePH
//
//  Created by lshenrong on 2018/8/9.
//  Copyright © 2018年 cedarhd. All rights reserved.
//

#import "CedarFileManager.h"

@implementation CedarFileManager


+ (BOOL)isFileExist:(NSString *)filePath{
    NSFileManager *fileManager = [NSFileManager defaultManager];
    BOOL result = [fileManager fileExistsAtPath:filePath];
    CLog(@"%@：%@",[filePath lastPathComponent],result?@"exist":@"no exist");
    return result;
}


+ (void)deleteFile:(NSString *)filePath{
    if([CedarFileManager isFileExist:filePath]){
        NSFileManager *fileManager = [NSFileManager defaultManager];
        BOOL result = [fileManager removeItemAtPath:filePath error:nil];
         CLog(@"%@：%@",[filePath lastPathComponent],result?@"delete ok":@"delete faile");
    }
}

+ (long long)fileSizeAtPath:(NSString*)filePath{
    NSFileManager* manager = [NSFileManager defaultManager];
    if ([manager fileExistsAtPath:filePath]){
        return [[manager attributesOfItemAtPath:filePath error:nil] fileSize];
    }
    return 0;
}


+ (NSString *)filePathAtCacheWithFolder:(NSString *)folder fileUrl:(NSString *)fileUrl fileName:(NSString *)fileName{
    if (IsEmptyStr(fileUrl)) {
        return @"";
    }
    NSString *cachePath = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES).firstObject;
    NSString *folderPath  = [cachePath stringByAppendingPathComponent:folder];
    NSString *savefileName = fileName;
    if (IsEmptyStr(fileName)) {
       savefileName = [fileUrl lastPathComponent];
    }
    NSString *filePath = [folderPath stringByAppendingPathComponent:savefileName];
    //NSString *fileName = [fileUrl pathExtension];
   // filePath = [filePath stringByAppendingPathExtension:fileName];
    return filePath;
}





@end
